<template>
  <section class="works-main">
    <el-dialog
      v-el-drag-dialog
      :close-on-click-modal="false"
      :visible.sync="visible"
      title="选择作品"
      fullscreen
      center
      @close="handleCancel()"
    >
      <section class="select-inner">
        <el-collapse-transition>
          <section v-show="searchshow" class="main-search merge">
            <span class="svg-container">
              <svg-icon icon-class="search" />
            </span>
            <el-input
              v-model.trim="listQuery.worksName"
              placeholder="输入作品名称搜索"
              class="search-input"
              @keyup.enter.native="handleFilter"
            />
            <section class="search-btn">
              <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
              <el-button type="primary" @click="handleReset">重置</el-button>
              <span class="search-more" @click="searchshow = !searchshow">
                更多筛选条件
                <i class="el-icon-arrow-down" />
              </span>
            </section>
          </section>
        </el-collapse-transition>
        <el-collapse-transition>
          <section v-show="!searchshow" class="main-search separate">
            <section class="search-inner">
              <el-row>
                <el-col :span="12">
                  <section class="search-inner-item">
                    <div class="item-label">作品名称</div>
                    <el-input
                      v-model.trim="search.worksName"
                      style="width: 90%;"
                      class="filter-item"
                      placeholder="请输入作品名称搜索"
                    />
                  </section>
                </el-col>
                <el-col :span="12">
                  <section class="search-inner-item">
                    <div class="item-label">姓名</div>
                    <el-input
                      v-model.trim="search.userName"
                      style="width: 90%;"
                      class="filter-item"
                      placeholder="请输入姓名搜索"
                    />
                  </section>
                </el-col>
                <el-col :span="12">
                  <div class="search-inner-item">
                    <div class="item-label">证件号</div>
                    <el-input
                      v-model.trim="search.idCard"
                      style="width: 80%"
                      class="filter-item"
                      placeholder="请输入证件号搜索"
                    />
                  </div>
                </el-col>
                <el-col :span="12">
                  <div class="search-inner-item">
                    <div class="item-label">手机号码</div>
                    <el-input
                      v-model.trim="search.phoneNum"
                      style="width: 80%"
                      class="filter-item"
                      placeholder="请输入手机号码搜索"
                    />
                  </div>
                </el-col>

              </el-row>
            </section>
            <section class="search-btn">
              <el-button type="primary" @click="handleFilter">搜索</el-button>
              <el-button type="primary" @click="handleReset">重置</el-button>
              <span class="search-more" @click="searchshow = !searchshow">
                精简筛选条件
                <i class="el-icon-arrow-up" />
              </span>
            </section>
          </section>
        </el-collapse-transition>
        <section class="main-table">
          <v-table
            :list="list"
            tag="worksManage2"
            :list-loading="listLoading"
            :filter-column="filtercolumn"
            :selection="true"
            @handleSelectionChange="handleSelectionChange"
          >
            <el-table-column
              label="操作"
              fixed="right"
              align="center"
              min-width="100"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button type="text" size="mini" @click="handleView(scope.row)">查看作品</el-button>
              </template>
            </el-table-column>
          </v-table>
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="listQuery.page"
            :limit.sync="listQuery.limit"
            @pagination="getList"
          />
        </section>
      </section>
      <div slot="footer" class="dialog-footer">
        <el-button style="padding: 8px 30px;" @click="handleCancel()">关 闭</el-button>
        <el-button type="primary" style="padding: 8px 30px;" @click="handleComit()">确 认</el-button>
      </div>

    </el-dialog>
    <works-preview v-if="worksPreviewStatus" :id="worksId" @closeSet="worksPreviewStatus = false" />
  </section>
</template>
<script>
import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
import { queryPage } from './api'
import elDragDialog from '@/directive/el-drag-dialog'
import CryptoJS from '@/utils/aesJiaJM'
import NewsSet from '@/views/activity/zjhd/components/NewsSet'
import WorksPreview from '@/views/activity/zjhd/components/WorksPreview'

export default {
  name: 'WorksManage',
  components: { Pagination, VTable, WorksPreview },
  directives: { elDragDialog },
  props: {
    solicitationId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      searchshow: true,
      listQuery: {
        page: 1,
        limit: 10,
        worksName: ''
      },
      search: {
        worksName: '',
        userName: '',
        phoneNum: '',
        idCard: ''
      },
      list: [],
      total: 0,
      listLoading: false,
      visible: false,
      view: '/API-DOCUMENT/file/download/',
      multipleSelection: [],
      worksId: '',
      worksPreviewStatus: false
    }
  },
  created() {
    this.visible = true
    this.getList()
  },
  methods: {
    handleCancel() {
      this.$emit('cancel')
    },
    handleComit() {
      if (this.multipleSelection.length > 0) {
        this.$emit('comit', this.multipleSelection)
      } else {
        this.$message({
          message: '请选择作品！',
          type: 'warning',
          duration: 1500
        })
      }
    },
    handleSelectionChange(arr) {
      this.multipleSelection = arr
    },
    filtercolumn(scope, item) {
      if (item === 'authorPhoneNumber' || item === 'authorIdNumber') {
        return scope.row[item] ? CryptoJS.$aesJieM(scope.row[item]) : '--'
      } else {
        return scope.row[item]
      }
    },

    handleReset() {
      this.listQuery.page = 1
      this.listQuery.worksName = ''
      for (const i in this.search) {
        if (this.search['' + i + ''] instanceof Array) {
          this.search['' + i + ''] = []
        } else {
          this.search['' + i + ''] = ''
        }
      }
      this.getList()
    },

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    handleCreate() {
      this.$router.push({ path: this.$filterPath('worksCreate'), query: {}})
    },
    handleCheck(row) {
      this.$router.push({ path: this.$filterPath('worksCheck'), query: { i: row.id, t: 'c' }})
    },
    handleView(row) {
      this.worksId = row.id
      this.worksPreviewStatus = true
      // this.$router.push({ path: this.$filterPath('worksCheck'), query: { i: row.id, t: 's' }})
      // this.$router.push({ path: '/activity/zjhd/worksCheck', query: { i: row.id, t: 's' }})
    },
    getList(obj) {
      this.listLoading = true
      var query = {
        page: obj ? obj.page : this.listQuery.page,
        pageSize: obj ? obj.limit : this.listQuery.limit,
        solicitationId: this.solicitationId
      }
      if (this.searchshow) {
        query['worksName'] = this.listQuery.worksName
      } else {
        query['worksName'] = this.search.worksName
        query['authorRealName'] = this.search.userName
        query['authorPhoneNumber'] = CryptoJS.$aesJiaM(this.search.phoneNum)
        query['authorIdNumber'] = CryptoJS.$aesJiaM(this.search.idCard)
      }
      return new Promise((resolve, reject) => {
        queryPage(query).then(response => {
          this.list = response.data.data.rows
          this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    }
  }
}
</script>
<style lang="scss">

.works-main {
  .select-inner {
    max-height: calc(100vh - 130px);
    min-height: calc(100vh - 130px);
    position: relative;
    padding: 10px;

  }

  .main-search {
    background-color: #fff;
    padding: 0 10px;

    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }

    .search-input {
      width: 60%;
      position: relative;

      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }

      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;

        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }

    .search-btn {
      display: inline-block;
      float: right;

      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }

      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }

    &.separate {
      .search-inner {
        padding-top: 10px;

        .search-inner-item {
          .item-label {
            height: 30px;
            line-height: 30px;
            font-size: 14px;
            color: #a6a6a6;
            font-weight: 400;
          }

          .el-input {
            position: relative;

            &.el-date-editor input {
              padding-left: 30px;
            }

            .el-input__inner {
              border: none;
              padding: 0;
            }

            &:after {
              content: '';
              height: 1px;
              background-color: #e2e3e8;
              position: absolute;
              left: 0;
              right: 0;
              bottom: 0;
            }
          }
        }
      }

      .search-btn {
        text-align: center;
        display: block;
        float: none;
        height: 56px;
        line-height: 56px;
      }
    }
  }

  .classify-tab {
    width: 100%;
    margin-bottom: 10px;
    padding: 0 10px;
    background-color: #fff;
    display: flex;
    border-radius: 4px;

    .el-tabs__nav-wrap::after {
      display: none;
    }

    .el-tabs__header {
      margin: 0;
    }
  }

  .main-buttons {
    display: flex;
    line-height: 36px;
    margin-top: 10px;

    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
    }
  }

  .el-dialog__footer {
    position: relative;
    padding: 20px !important;

    &::after {
      content: '';
      height: 1px;
      background-color: #e2e3e8;
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
    }
  }
}
</style>
